package com.zvfe.common;

import lombok.Data;

/**
 * 所有数据统一的返回值
 */
@Data
public class R {
    private int code;   //200表示成功  400表示失败
    private String msg; //返回的提示信息
    private Long total; //返回数据的总数
    private Object data;  //返回的数据

    //返回的最基本的数据
    private static R result(int code,String msg,Long total,Object data){
        R result=new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setTotal(total);
        result.setData(data);
        return result;
    }

    //成功的数据
    public static R success(Object data,Long total){
        return result(200,"成功",total,data);
    }

    public static R success(){
        return result(200,"成功",0L,null);
    }

    public static R success(Object data) {
        return result(200, "成功", 0L, data);
    }
    //失败的数据
    public static R err(){
        return result(400,"失败",0L,null);
    }
}
